import axios from 'axios'
export default {
    getDate(page, callback) {
        axios.get(`${global.ApiUrl}/foods?page=${page}`)
            .then(res => {
                callback(res.data)
            })
            .catch(err => {
                console.log(err)
            })
    },
    getDataById(id, callback) {
        axios.get(`${global.ApiUrl}/foods/${id}`)
            .then(res => {
                delete res.data.data.__v 
                delete res.data.data._id
                callback(res.data)
            })
            .catch(err => {
                console.log(err)
            })
    },
    update(id,data,img,callback){
        axios.post(`${global.ApiUrl}/foods/update/${id}?img=${img}`,data)
            .then(res => {
                callback(res.data)
            })
            .catch(err => {
                console.log(err)
            })
    },
    
    save(data, callback) {
        axios.post(`${global.ApiUrl}/foods/create`, data)
            .then(res => {
                console.log(data)
                callback(res.data)
            })
            .catch(err => {
                console.log(err)
            })
    },
    delete(id,img, callback) {
        axios.post(`${global.ApiUrl}/foods/delete/${id}?img=${img}`)
            .then(res => {
                callback(res.data)
            })
            .catch(err => {
                console.log(err)
            })
    }
}